package prison.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.shwread.android.qysw10000000.R;

import java.util.List;

import prison.bean.PrisonBean;

/**
 * Created by lex on 2017/3/13.
 */

public class SelectPrisonAdapter extends BaseAdapter {
    private Context context;
    private List<PrisonBean> itemList;

    public SelectPrisonAdapter(Context context, List<PrisonBean> itemList) {
        this.context = context;
        this.itemList = itemList;
    }

    @Override
    public int getCount() {
        return itemList.size();
    }

    @Override
    public Object getItem(int i) {
        return itemList.size();
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder mh = null;
        if (view == null) {
            mh = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.pop_item, null);
            mh.tvPopitemName = (TextView) view.findViewById(R.id.tvPopitemName);
            mh.popDeliver = view.findViewById(R.id.popDeliver);
            view.setTag(mh);
        } else {
            mh = (ViewHolder) view.getTag();
        }
        mh.tvPopitemName.setText(itemList.get(i).getName());
        if (i == itemList.size() - 1) {
            mh.popDeliver.setVisibility(View.GONE);
        } else {
            mh.popDeliver.setVisibility(View.VISIBLE);
        }
        return view;
    }

    class ViewHolder {
        TextView tvPopitemName;
        View popDeliver;
    }
}
